﻿/*!	@file	r_input_device_controll.h
	@brief	入力装置
Copyright (c) 2009 Yuya Yamaguchi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _R_INPUT_DEVICE_CONTROLL_H_
#define _R_INPUT_DEVICE_CONTROLL_H_

#include "r_input_param.h"
#include "r_input_device.h"

namespace r{
	namespace input{
		//! アナログ入力
		struct Analog2D {
			Analog2D()
				:
				x ( 0 ), y ( 0 ) {}
			Analog2D ( r_f32 _x, r_f32 _y )
				:
				x ( _x ), y ( _y ) {}
			r_f32		x;
			r_f32		y;
		};
		//! スクリーン入力
		struct Screen {
			Screen()
				:
				x ( 0 ), y ( 0 ) {}
			Screen ( r_si32 _x, r_si32 _y )
				:
				x ( _x ), y ( _y ) {}
			r_si32		x;
			r_si32		y;
		};

		enum DeviceControllKeys {
			DeviceControllKeys_Start	= 0,
			DeviceControllKeys_Select,
			DeviceControllKeys_Up,
			DeviceControllKeys_Down,
			DeviceControllKeys_Left,
			DeviceControllKeys_Right,
			DeviceControllKeys_A,
			DeviceControllKeys_B,
			DeviceControllKeys_C,
			DeviceControllKeys_D,
			DeviceControllKeys_E,
			DeviceControllKeys_F,
			DeviceControllKeys_L1,
			DeviceControllKeys_R1,
			DeviceControllKeys_L2,
			DeviceControllKeys_R2,
			DeviceControllKeys_DNum,	// 16
			DeviceControllKeys_PointL = DeviceControllKeys_DNum,	//!< 左ボタン
			DeviceControllKeys_PointM,							//!< 中ボタン
			DeviceControllKeys_PointR,							//!< 右ボタン
			DeviceControllKeys_PNum,	// 19
			DeviceControllKeys_AD_L_Up = DeviceControllKeys_DNum,	//!< 左デジタルアナログ
			DeviceControllKeys_AD_L_Down,						//!< 左デジタルアナログ
			DeviceControllKeys_AD_L_Left,						//!< 左デジタルアナログ
			DeviceControllKeys_AD_L_Right,						//!< 左デジタルアナログ
			DeviceControllKeys_AD_R_Up,							//!< 右デジタルアナログ
			DeviceControllKeys_AD_R_Down,						//!< 右デジタルアナログ
			DeviceControllKeys_AD_R_Left,						//!< 右デジタルアナログ
			DeviceControllKeys_AD_R_Right,						//!< 右デジタルアナログ
			DeviceControllKeys_AD_L1,							//!< デジタルアナログ
			DeviceControllKeys_AD_R1,							//!< デジタルアナログ
			DeviceControllKeys_AD_L2,							//!< デジタルアナログ
			DeviceControllKeys_AD_R2,							//!< デジタルアナログ
			DeviceControllKeys_Num
		};
		enum DeviceControllKeyMask {
			DeviceControllKeyMask_Start			= 1 << DeviceControllKeys_Start,
			DeviceControllKeyMask_Select		= 1 << DeviceControllKeys_Select,
			DeviceControllKeyMask_Up			= 1 << DeviceControllKeys_Up,
			DeviceControllKeyMask_Down			= 1 << DeviceControllKeys_Down,
			DeviceControllKeyMask_Left			= 1 << DeviceControllKeys_Left,
			DeviceControllKeyMask_Right			= 1 << DeviceControllKeys_Right,
			DeviceControllKeyMask_A				= 1 << DeviceControllKeys_A,
			DeviceControllKeyMask_B				= 1 << DeviceControllKeys_B,
			DeviceControllKeyMask_C				= 1 << DeviceControllKeys_C,
			DeviceControllKeyMask_D				= 1 << DeviceControllKeys_D,
			DeviceControllKeyMask_L1			= 1 << DeviceControllKeys_L1,
			DeviceControllKeyMask_R1			= 1 << DeviceControllKeys_R1,
			DeviceControllKeyMask_L2			= 1 << DeviceControllKeys_L2,
			DeviceControllKeyMask_R2			= 1 << DeviceControllKeys_R2,
			DeviceControllKeyMask_PointL		= 1 << DeviceControllKeys_PointL,
			DeviceControllKeyMask_PointM		= 1 << DeviceControllKeys_PointM,
			DeviceControllKeyMask_PointR		= 1 << DeviceControllKeys_PointR,
			DeviceControllKeyMask_AD_L_Up		= 1 << DeviceControllKeys_AD_L_Up,
			DeviceControllKeyMask_AD_L_Down		= 1 << DeviceControllKeys_AD_L_Down,
			DeviceControllKeyMask_AD_L_Left		= 1 << DeviceControllKeys_AD_L_Left,
			DeviceControllKeyMask_AD_L_Right	= 1 << DeviceControllKeys_AD_L_Right,
			DeviceControllKeyMask_AD_R_Up		= 1 << DeviceControllKeys_AD_R_Up,
			DeviceControllKeyMask_AD_R_Down		= 1 << DeviceControllKeys_AD_R_Down,
			DeviceControllKeyMask_AD_R_Left		= 1 << DeviceControllKeys_AD_R_Left,
			DeviceControllKeyMask_AD_R_Right	= 1 << DeviceControllKeys_AD_R_Right,
			DeviceControllKeyMask_AD_L1			= 1 << DeviceControllKeys_AD_L1,
			DeviceControllKeyMask_AD_R1			= 1 << DeviceControllKeys_AD_R1,
			DeviceControllKeyMask_AD_L2			= 1 << DeviceControllKeys_AD_L2,
			DeviceControllKeyMask_AD_R2			= 1 << DeviceControllKeys_AD_R2
		};
		enum DeviceControllKeyAnalog {
			DeviceControllKeyAnalog_L1			= 0,
			DeviceControllKeyAnalog_R1,
			DeviceControllKeyAnalog_L2,
			DeviceControllKeyAnalog_R2,
			DeviceControllKeyAnalog_Num
		};
		enum DeviceControllKeyAnalog2D {
			DeviceControllKeyAnalog2D_L			= 0,
			DeviceControllKeyAnalog2D_R,
			DeviceControllKeyAnalog2D_Num
		};

		//! 入力デバイス状態
		/*!
		*/
		class DeviceControll : public Device
		{
			RRTTI_REFLECTION_DECLARE
		public:
			//! コンストラクタ
			DeviceControll();
			//! デストラクタ
			virtual ~DeviceControll();
		public:
			//! 入力キーの取得
			/*!
			*/
			r_ui32					getAllKeyPress ( void ) const;
			///
			/*!
			*/
			r_ui32					getAllKeyPush ( void ) const;
			///
			/*!
			*/
			r_ui32					getAllKeyRelease ( void ) const;
			///
			/*!
			*/
			r_ui32					getAllKeyRepeat ( void ) const;
			//! キーの押下カウントの取得
			/*!
			*/
			r_ui32					getKeyCount ( r_ui32 keyID ) const;
			// アナログ
			//! 1方向のアナログキーの取得
			/*!
			*/
			r_f32					getAnalog ( r_ui32 analogID ) const;
			//! 2方向のアナログキーの取得
			/*!
			*/
			void					getAnalog2D ( r_ui32 analog2dID, Analog2D& data ) const;
			//! 画面直接入力
			/*!
			*/
			const Screen&	getScreen ( void ) const;

		protected:
			r_ui32				keyAllPress;			//!< 全部のキー
			r_ui32				keyAllPush;				//!< 全部押した
			r_ui32				keyAllRelease;			//!< 全部放した
			r_ui32				keyAllRepeat;			//!< 全部のリピート入力
			r_ui32				keyCount[DeviceControllKeys_Num];	//!< キー押下カウント
		protected:
			r_bool				key[DeviceControllKeys_Num];				//!< キー情報
			r_f32				analog[DeviceControllKeyAnalog_Num];		//!< アナログ情報
			Analog2D	analog2D[DeviceControllKeyAnalog2D_Num];	//!< 2Dアナログ情報
			Screen		screen;					//!< スクリーン情報
		private:
		};
	}
}

#endif // _R_INPUT_DEVICE_CONTROLL_H_
